package com.ruoyi.web.controller.compensationManagement;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.compensationManagement.domain.CompensationRetireeSubsidyProject;
import com.ruoyi.compensationManagement.service.ICompensationRetireeSubsidyProjectService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 退休人员补贴项目设置Controller
 *
 * @author zy
 * @date 2022-10-07
 */
@RestController
@RequestMapping("/compensationManagement/setRetireeSubsidyItems")
public class CompensationRetireeSubsidyProjectController extends BaseController {
    @Autowired
    private ICompensationRetireeSubsidyProjectService compensationRetireeSubsidyProjectService;

    /**
     * 查询退休人员补贴项目设置列表
     */
    @PreAuthorize("@ss.hasPermi('compensationManagement:setRetireeSubsidyItems:list')")
    @GetMapping("/list")
    public TableDataInfo list(CompensationRetireeSubsidyProject compensationRetireeSubsidyProject) {
        startPage();
        List<CompensationRetireeSubsidyProject> list = compensationRetireeSubsidyProjectService.selectCompensationRetireeSubsidyProjectList(compensationRetireeSubsidyProject);
        return getDataTable(list);
    }

    /**
     * 导出退休人员补贴项目设置列表
     */
    @PreAuthorize("@ss.hasPermi('compensationManagement:setRetireeSubsidyItems:export')")
    @Log(title = "退休人员补贴项目设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CompensationRetireeSubsidyProject compensationRetireeSubsidyProject) {
        List<CompensationRetireeSubsidyProject> list = compensationRetireeSubsidyProjectService.selectCompensationRetireeSubsidyProjectList(compensationRetireeSubsidyProject);
        ExcelUtil<CompensationRetireeSubsidyProject> util = new ExcelUtil<CompensationRetireeSubsidyProject>(CompensationRetireeSubsidyProject.class);
        util.exportExcel(response, list, "退休人员补贴项目设置数据");
    }

    /**
     * 获取退休人员补贴项目设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('compensationManagement:setRetireeSubsidyItems:query')")
    @GetMapping(value = "/{subsidyprojectId}")
    public AjaxResult getInfo(@PathVariable("subsidyprojectId") Long subsidyprojectId) {
        return AjaxResult.success(compensationRetireeSubsidyProjectService.selectCompensationRetireeSubsidyProjectBySubsidyprojectId(subsidyprojectId));
    }

    /**
     * 新增退休人员补贴项目设置
     */
    @PreAuthorize("@ss.hasPermi('compensationManagement:setRetireeSubsidyItems:add')")
    @Log(title = "退休人员补贴项目设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CompensationRetireeSubsidyProject compensationRetireeSubsidyProject) {
        return toAjax(compensationRetireeSubsidyProjectService.insertCompensationRetireeSubsidyProject(compensationRetireeSubsidyProject));
    }

    /**
     * 修改退休人员补贴项目设置
     */
    @PreAuthorize("@ss.hasPermi('compensationManagement:setRetireeSubsidyItems:edit')")
    @Log(title = "退休人员补贴项目设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CompensationRetireeSubsidyProject compensationRetireeSubsidyProject) {
        return toAjax(compensationRetireeSubsidyProjectService.updateCompensationRetireeSubsidyProject(compensationRetireeSubsidyProject));
    }

    /**
     * 删除退休人员补贴项目设置
     */
    @PreAuthorize("@ss.hasPermi('compensationManagement:setRetireeSubsidyItems:remove')")
    @Log(title = "退休人员补贴项目设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{subsidyprojectIds}")
    public AjaxResult remove(@PathVariable Long[] subsidyprojectIds) {
        if (subsidyprojectIds[0] == 1 || subsidyprojectIds[0] == 2 || subsidyprojectIds[0] == 3) {
            return AjaxResult.error("固定项目已固定，无法删除");
        } else {
            return toAjax(compensationRetireeSubsidyProjectService.deleteCompensationRetireeSubsidyProjectBySubsidyprojectIds(subsidyprojectIds));
        }
    }

    /**
     * 查所有浮动项目下拉选项
     */
    @GetMapping("/getAllFloatingItems")
    public AjaxResult getAllFloatingItems() {
        return AjaxResult.success(compensationRetireeSubsidyProjectService.getAllFloatingItems());
    }
}
